//
//  AXMyActivitySpellDetailsVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/13.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXMyActivitySpellDetailsVC.h"
#import "UIViewController+HBD.h"
#import "AXSpellDetailsFirstCell.h"
#import "AXSpellDetailsSecondCell.h"
#import "AXSpellDetailsThirdCell.h"
#import "AXSpellDetailsFirstModel.h"
#import "AXSpellDetailsSecondModel.h"
#import "AXSpellDetailsThirdModel.h"
#import "UITableView+SDAutoTableViewCellHeight.h"

@interface AXMyActivitySpellDetailsVC ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic , strong) NSMutableArray<AXSpellDetailsFirstModel *> *firModelsArray;
@property (nonatomic , strong) NSMutableArray<AXSpellDetailsSecondModel *> *secModelsArray;
@property (nonatomic , strong) NSMutableArray<AXSpellDetailsThirdModel *> *thrModelsArray;

@property (nonatomic ,strong) UITableView *tableView;


@end

@implementation AXMyActivitySpellDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatView];
    [self setlayout];
    [self setupNavigationItems];
    // Do any additional setup after loading the view.
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    
    
}



- (void)creatView {
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [self.tableView   setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.tableView.delegate = self;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.dataSource = self;
    [self.tableView registerClass:[AXSpellDetailsFirstCell class] forCellReuseIdentifier:[AXSpellDetailsFirstCell reuseID]];
    [self.tableView registerClass:[AXSpellDetailsSecondCell class] forCellReuseIdentifier:[AXSpellDetailsSecondCell reuseID]];
    [self.tableView registerClass:[AXSpellDetailsThirdCell class] forCellReuseIdentifier:[AXSpellDetailsThirdCell reuseID]];
    [self.view addSubview:self.tableView];
    
    
}

- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, Hn)
    .widthIs(Wi)
    .heightIs((TableViewHeight));
}


- (void)setupNavigationItems {
    
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    /** title */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"拼单详情";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
}

- (void)backAction:(UIBarButtonItem *)item {
    
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - tableview delegate & tableviewdatasource

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    
    return [UIView new];
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
   
    
    return 0;
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0;
}


//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return 1;
}

/** cell的高度 */

/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        
      return [tableView cellHeightForIndexPath:indexPath model:self.firModelsArray[indexPath.row] keyPath:@"model" cellClass:[AXSpellDetailsFirstCell class] contentViewWidth:SCREEN_WIDTH];
        
    }
    else if (indexPath.section == 1){
        
        return  140;
        
//          return [tableView cellHeightForIndexPath:indexPath model:self.secModelsArray[indexPath.row] keyPath:@"model" cellClass:[AXSpellDetailsSecondCell class] contentViewWidth:SCREEN_WIDTH];
        
      
    }
    
 return [tableView cellHeightForIndexPath:indexPath model:self.thrModelsArray[indexPath.row] keyPath:@"model" cellClass:[AXSpellDetailsThirdCell class] contentViewWidth:SCREEN_WIDTH];
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        AXSpellDetailsFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXSpellDetailsFirstCell reuseID] forIndexPath:indexPath];
        /** 取消cell的选中效果 */
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        return cell;
    }
    
    else if (indexPath.section == 1) {
        
        AXSpellDetailsSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXSpellDetailsSecondCell reuseID] forIndexPath:indexPath];
        /** 取消cell的选中效果 */
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }
    
    AXSpellDetailsThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXSpellDetailsThirdCell reuseID] forIndexPath:indexPath];
    /** 取消cell的选中效果 */
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
    
    
}


@end
